<?php
/**
 * Created by PhpStorm.
 * User: Peco
 * Date: 2019/9/22
 * Time: 10:25
 */

namespace App\Models;


use Carbon\Carbon;

class AuctionGoodsInfo extends BaseModel
{
    /**
     * 与模型关联的数据表
     *
     * @var string
     */
    protected $table = 'auction_goods_info';

    /**
     * 主键
     * @var string
     */
    protected $primaryKey = 'id';

    /**
     * 需要被转换成日期的属性。
     *
     * @var array
     */
    protected $dates = ['end_times', 'start_times'];

    /**
     * @var array
     */
    protected $guarded = ['id'];

    /**
     * @var array
     */
    protected $hidden = ['deleted_at'];

    /**
     * @var array
     */
    protected $appends = [];

    /**
     * 所属商品信息
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function goods(){
        return $this->belongsTo(Goods::class, 'goodsId', 'id');
    }

    /**
     * 该商品所有竞拍记录
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function userAuctionRecord(){
        return $this->hasMany(UserAuctionRecord::class, 'auctionId', 'auctionId');
    }

    /**
     * 该商品最后一条竞拍记录
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function lastUserAuctionRecord(){
        return $this->hasOne(UserAuctionRecord::class, 'auctionId', 'auctionId')
            ->latest('markUpTime');
    }



}
